package cn.edu.scau.cmi.xiaozhenlin.multipleton;

import java.util.ArrayList;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class MultipletonController {

	@FXML
	private TextArea tv_show;

	@FXML
	private TextField et_input;

	ArrayList<Marshal> list;

	@FXML
	void newMarshal(ActionEvent event) {
		tv_show.clear();
		String mString = et_input.getText();
		list = Marshal.getInstance(et_input.getText());
		if (list.size() != 10) {
			tv_show.setText("添加元帅：" + mString);
		} else {
			tv_show.setText("添加失败！人数已达上限");
		}

	}

	@FXML
	void showMarshal(ActionEvent event) {
		tv_show.clear();
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			stringBuilder.append("第" + (i + 1) + "位元帅是：" + list.get(i).getName() + "\n");

		}
		tv_show.setText(stringBuilder.toString());
	}

}
